#include <stdio.h>
#include <stdlib.h>

#include "list.h"

struct data_st {
	int num;
	struct list_head node;
};

int main(void)
{
	int i;
	struct data_st *d = NULL;
	struct list_head *pos;
	int key = 6;

	// 初始化头结点
	LIST_HEAD(mylist);	

	for (i = 1; i <= 10; i++) {
		d = malloc(sizeof(*d /*struct data_st*/));	
		d->num = i;
		list_add(&d->node, &mylist);
	}

	// 比对找到数据是key结点
	list_for_each(pos, &mylist) {
		d = list_entry(pos, struct data_st, node); // container_of
		if (d->num == key) {
			list_del(&d->node);
			free(d);
			d = NULL;
			break;
		}
	}

	list_for_each(pos, &mylist) {
		// pos结点的node的地址
		d = list_entry(pos, struct data_st, node);
		printf("%d ", d->num);
	}
	printf("\n");

	return 0;
}


